package rs.daolao.syc.admin.account.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import rs.dalao.syc.common.ex.ServiceException;
import rs.dalao.syc.common.response.ServiceCode;
import rs.daolao.syc.admin.account.dao.persist.repository.IDocRepository;
import rs.daolao.syc.admin.account.pojo.vo.DoctorSearchVO;
import rs.daolao.syc.admin.account.service.IDoctorService;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
@Slf4j
@Service
public class DoctorServiceImpl implements IDoctorService {
    @Override
    public void rebuildSearch() {

    }

    @Autowired
    private IDocRepository iDocRepository;


    @Override
    public List<DoctorSearchVO> customQueryDoctor(String title) {
        return null;
    }

    @Override
    public void deleteDoc(Long id) {
        log.debug("开始处理【根据ID删除用户】的业务，参数：{}", id);
        if (id == 1) {
            String message = "删除用户失败，尝试访问的数据不存在！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_NOT_FOUND, message);
        }

        Object queryResult = iDocRepository.getStandardById(id);
        if (queryResult == null) {
            String message = "删除用户失败，尝试访问的数据不存在！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_NOT_FOUND, message);
        }

        log.debug("即将执行删除数据，参数：{}", id);
        int rows = iDocRepository.deleteById(id);
        if (rows != 1) {
            String message = "删除用户失败，服务器忙，请稍后再尝试！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_DELETE, message);
        }

        log.debug("即将执行删除关联数据，参数：{}", id);

        if (rows < 1) {
            String message = "删除用户失败，服务器忙，请稍后再尝试！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_DELETE, message);
        }

        log.debug("即将删除缓存中的账号状态数据，无参数");
        iDocRepository.deleteById(id);
    }
}
